package com.han;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Demo {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/succ?useSSL=false&useUnicode=true&CharacterEncoding=GBK&serverTimezone=UTC";
            String username = "root";
            String password =  "root";
            Connection con = DriverManager.getConnection(url,username,password);
            Statement statement = con.createStatement();
            String sql = "SELECT stu_name as studentname,MAX(stu_score)-MIN(stu_score) from student GROUP BY stu_name";
          /*  测试结果返回true 查询成功 boolean execute = statement.execute(sql);
            System.out.println(execute);*/
            ResultSet resultSet = statement.executeQuery(sql);
            while(resultSet.next()){
                String name = resultSet.getString(1);
                int resultScore = resultSet.getInt(2);
                System.out.println(name+","+resultScore);
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
